import std.stdint;
import sdlang;

enum DefRegister : ushort
{
	R0, R1, R2, R3, R4, R5, R6, R7,
	R8, R9, R10, R11, R12, R13, R14,
	R15, R16, R17, R18, R19, R20, R21,
	R22, R23, R24, R25, R26, R27, R28,
	R29, R30, R31
}

enum OperandFlag
{
	AnyRegister = 1,
	R16_31Register,
	EvenRegister,
	R16_23Register,
	WordRegister,
	PointerRegister,
	BasePtrRegister,
	ZPointerRegister,
	Immediate8bit,
	Immediate8bitNoReloc,
	IOPort6Bit,
	IOPort5Bit,
	Immediate,
	SignedPCOffset64,
	SignedPCOffset2k,
	AbsoluteAddress,
	BitValue
}
	
struct Operand(T)
{
	this(string n, OperandFlag f, T mi, T ma)
	{
		name = n; flag = f; min = mi; max = ma;
		sym = '?'; val = 0; desc = ""; mask = 0;
	}
	string name;
	DefRegister num;
	char sym;
	T val;
	OperandFlag flag;
	T min, max;
	string desc;
	T mask;
}

struct Instruction(T)
{
	this(string n, ubyte b, ubyte no=0, T c=0, T m=0)
	{
		name = n; bits = b; numOperands = no;
		code = c; mask = m;
		if (no)
			operands = new Operand!T[numOperands];
	}
	
	string name;
	T code;
	T mask;
	ubyte	bits;
	ubyte	numOperands;
	Operand!T [] operands;
}

Instruction!uint16_t [string] instr16;

